const searchGarbage = require('../../../utils/garbage-search.js');

//查询垃圾分类信息
Page({
  data: {
    datas: [],
    searchText: ""
  },
  //从图片、语音搜索跳转时 设置搜索词并搜索
  onLoad: function (query) {
    if (query.searchText) {
      search(query.searchText, this);
    }
  },
  //输入并确认搜索
  onConfirm: function (e) {
    if (!e.detail.value) {
      return
    }
    search(e.detail.value, this)
  },
})

function search(text, pageRef) {
  var searchResult = []
  pageRef.setData({
    searchText: text
  });
  searchGarbage.search(text, res => {
    console.log('searchResult:' + JSON.stringify(res));
    searchResult = res;
    pageRef.setData({
      datas: searchResult
    })
  })
}